import unittest
from Public import HTMLTestReportCNPy3
import os
import time
dir=os.path.abspath(os.curdir)
result = dir+"\\Result\\"

from TestCase.Test_Login import Test_Login
from TestCase.Test_Noscanning import Test_Noscanning
from TestCase.Test_Policyholder import Test_Policyholder
from TestCase.Test_InsuredMt import Test_InsuredMt
from TestCase.Test_Review import Test_Review
from TestCase.Test_ManReview import Test_ManReview
from TestCase.Test_Bank import Test_Bank
from TestCase.Test_Session import Test_Session
from TestCase.Test_ChargeManager import Test_ChargeManager
from TestCase.Test_Issue import Test_Issue
from TestCase.Test_PlanMaintenence import Test_PlanMaintenence




#创建测试集
def CreateSuite():
    suite = unittest.TestSuite()

    # case1 =unittest.TestLoader().loadTestsFromTestCase(Test_Login)
    # case1=unittest.TestLoader().loadTestsFromTestCase(Test_Noscanning)
    case2=unittest.TestLoader().loadTestsFromTestCase(Test_PlanMaintenence)
    case3 = unittest.TestLoader().loadTestsFromTestCase(Test_InsuredMt)
    case4 = unittest.TestLoader().loadTestsFromTestCase(Test_Policyholder)
    case5 = unittest.TestLoader().loadTestsFromTestCase(Test_Review)
    case6 = unittest.TestLoader().loadTestsFromTestCase(Test_ManReview)
    case7 = unittest.TestLoader().loadTestsFromTestCase(Test_Bank)
    case8 = unittest.TestLoader().loadTestsFromTestCase(Test_Session)
    case9 = unittest.TestLoader().loadTestsFromTestCase(Test_ChargeManager)
    case10 = unittest.TestLoader().loadTestsFromTestCase(Test_Issue)

    # suite.addTest(case1)
    # suite.addTest(case1)
    suite.addTest(case2)
    suite.addTest(case3)
    suite.addTest(case4)
    suite.addTest(case5)
    suite.addTest(case6)
    suite.addTest(case7)
    suite.addTest(case8)
    suite.addTest(case9)
    suite.addTest(case10)


    return suite

#生成报告
def run():
    suite = CreateSuite()
    day = time.strftime('%Y-%m-%d',time.localtime(time.time()))
    rep_dir= result+day
    if not os.path.exists(rep_dir):
        os.makedirs(rep_dir)
    filename=rep_dir+'\\'+"result.html"
    f = open(filename,'wb')
    runner=HTMLTestReportCNPy3.HTMLTestRunner(stream=f,title='测试报告',description='第一次运行测试报告')
    runner.run(suite)
    f.close()

run()